<template>
  <div class="app-container">
    <div class="search-container">
      <el-form :model="searchParam" :inline="true">
        <el-form-item label="工作中心编号">
          <el-input
            v-model="searchParam.workCenterCode"
            placeholder="请输入工作中心编号"
            clearable
            @keyup.enter="search"
          />
        </el-form-item>
        <el-form-item label="存储编号">
          <el-input
            v-model="searchParam.materialCode"
            placeholder="请输入存储编号"
            clearable
            @keyup.enter="search"
          />
        </el-form-item>
        <el-form-item label="批次">
          <el-input
            v-model="searchParam.materialBatch"
            placeholder="请输入批次"
            clearable
            @keyup.enter="search"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search"
            ><i-ep-search />搜索</el-button
          >
          <el-button @click="reset"><i-ep-refresh />重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-card shadow="never" class="table-container">
      <template #header>
        <el-button
          class="ml-3"
          @click="
            useDownload(
              '/mes/mesproducingstock/queryProducingStockStatisticalExport',
              '线边库存统计',
              searchParam
            )
          "
        >
          <template #icon><i-ep-download /></template>导出</el-button
        >
      </template>

      <el-table
        ref="dataTableRef"
        v-loading="loading"
        :data="tableData"
        highlight-current-row
        border
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column
          label="工作中心"
          prop="workCenterCode"
          min-width="200"
          show-overflow-tooltip
        >
          <template #default="scope">
            {{ scope.row.workCenterCode }} - {{ scope.row.workCenterName }}
          </template>
        </el-table-column>
        <el-table-column
          label="物料"
          prop="materialCode"
          min-width="200"
          show-overflow-tooltip
        >
          <template #default="scope">
            {{ scope.row.materialCode }} - {{ scope.row.materialName }}
          </template>
        </el-table-column>
        <el-table-column
          label="批次"
          prop="materialBatch"
          min-width="150"
          show-overflow-tooltip
        />
        <el-table-column
          label="数量"
          prop="materialQuantity"
          min-width="150"
          show-overflow-tooltip
          header-align="center"
          align="right"
        />
        <el-table-column
          label="数量单位"
          prop="quantityUnit"
          min-width="100"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">{{ useDictionary("MeasurementUnit", scope.row.quantityUnit ) }}</template>
        </el-table-column>
      </el-table>

      <el-pagination
        :background="true"
        :current-page="pageable.pageNum"
        :page-size="pageable.pageSize"
        :page-sizes="[10, 25, 50, 100]"
        :total="pageable.total"
        layout="total, sizes, prev, pager, next, jumper"
        class="mt-[20px]"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { useTable, useDownload, useDictionary } from "@/utils/useTable";
import request from "@/utils/request";

defineOptions({
  name: "PRODUCINGSTOCKRECORD",
  inheritAttrs: false,
});

// 请求参数
const requestApi = "/mes/mesproducingstock/queryProducingStockStatistical";

// 是否需要分页
const pagination = true;

const initParam = {};

// 初始化搜索参数数据
const searchParamInit = {
  materialCode: "",
  materialBatch: "",
  workCenterCode: "",
};

const deleteParam = {
  api: "/mes/mesmaterialonlinerecord/delete",
  data: {},
};

// 数据请求错误后处理
function requestError() {}

const dataCallBack = ref(undefined); // 无需二次数据处理&不传赞数也行

// 表格操作 Hooks
const {
  tableData,
  pageable,
  searchParam,
  ids,
  getTableList,
  search,
  reset,
  handleSizeChange,
  handleCurrentChange,
  handleSelectionChange,
  handleTableDelete,
  loading,
}: any = useTable(
  requestApi,
  initParam,
  searchParamInit,
  pagination,
  dataCallBack.value,
  requestError,
  deleteParam
);

onMounted(() => {
  getTableList();
});


</script>
